import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig(({ command, mode }) => {
  const baseConfig = {
    root: './',
    plugins: [react()],
    css: {
      preprocessorOption: {
        sass: {
          globalVars: {} //全局变量
        }
      },
      devSourcemap: false
    },
  };

  if( mode === 'serve') {
    return Object.assign(baseConfig, {
      mode: 'development'
    });
  }

  return Object.assign(baseConfig, {
    mode: 'production',
    server: {
      host: '0.0.0.0',
      port: 3000,
    }
  });
});
